package com.parleys.activity;

import java.util.List;

import roboguice.inject.InjectView;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

import com.google.inject.Inject;
import com.parleys.R;
import com.parleys.adapter.ParleysListAdapter;
import com.parleys.domain.Channel;
import com.parleys.domain.Presentation;
import com.parleys.domain.Space;
import com.parleys.helper.ApplicationConstants;
import com.parleys.service.intf.ParleysService;
import com.parleys.service.intf.PresentationAssetsService;

/**
 * Displays all of a user's downloads
 */
public class MyDownloadsActivity extends AbstractParleysActivity {

	private static final Space NULL_SPACE = new Space();
	private static final Channel NULL_CHANNEL = new Channel();

	@Inject
	private ParleysService parleysService;

	@Inject
	private PresentationAssetsService presentationAssetsService;

	@InjectView(R.id.list)
	protected ListView listView;

	public MyDownloadsActivity() {
		setCustomTitleEnabled(true);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		List<Presentation> presentations = parleysService.getDownloadedPresentations();
		setContentView(R.layout.parleys_list);
		setTitle(getString(R.string.my_downloads));

		listView.setAdapter(new ParleysListAdapter(this, presentations, null, presentationAssetsService));
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) {
				Presentation presentation = (Presentation) listView.getItemAtPosition(position);
				Intent intent = new Intent(MyDownloadsActivity.this, PresentationDetailActivity.class) //
						.putExtra(ApplicationConstants.PRESENTATION_ARG, presentation) //
						.putExtra(ApplicationConstants.ONLINE_ARG, false) //
						.putExtra(ApplicationConstants.CHANNEL_ARG, NULL_CHANNEL) //
						.putExtra(ApplicationConstants.SPACE_ARG, NULL_SPACE); //

				startActivity(intent);
			}
		});

	}

}
